import { Injectable } from '@nestjs/common';
import { DistrictModelService } from 'src/model/district-model/district-model.service';
import { In } from 'typeorm';

@Injectable()
export class DistrictService {
    constructor(
        private model:DistrictModelService
    ){}

    getDistrictByParentId(parentId:number) {
        return this.model.find({ parentId })
    }

    async getDistrictMapByIds(ids:number[]) {
        const districtMap:{[key:number] : string} = {}
        const data = await this.model.find({id : In(ids)}, ['id', 'name'])
        data.forEach(item => {
            districtMap[item.id] = item.name
        })

        return districtMap

    }
}
